package com.bdqn.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bdqn.crm.mapper.SysUserMapper;
import com.bdqn.crm.pojo.SysUser;
import com.bdqn.crm.service.SysUserService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
        implements SysUserService {

    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser login(String usrName, String usrPassword) {
        return sysUserMapper.login(usrName, usrPassword);
    }

    @Override
    public List<SysUser> selectPages(String usrName, Long roleId, Integer pageIndex, Integer pageSize) {
        return sysUserMapper.selectPages(usrName, roleId, pageIndex, pageSize);
    }

    /**
     * 登錄
     *
     * @param usrName
     * @param usrPassword
     * @return
     */
    @Override
    public List<SysUser> findUsersByUsrNameAndUsrPassword(String usrName, String usrPassword) {

        return null;
    }


    /**
     * 根据用户名查询用户对象
     *
     * @param usrName
     * @return
     */
    @Override
    public SysUser findUserByUsrName(String usrName) {
        return sysUserMapper.findUserByUsrName(usrName);
    }

    /**
     * 输入明文密码得到密文密码
     *
     * @param plaintextPassword
     * @return
     * @throws IllegalArgumentException
     */
    @Override
    public String encryptPassword(Object plaintextPassword) throws IllegalArgumentException {
        String salt = "czkt";
        Md5Hash md5Hash = new Md5Hash(plaintextPassword,salt,2);
        return md5Hash.toString();
    }
}




